
CREATE OR REPLACE PACKAGE s_general_pkg
AS
   /******************************************************************************
      NAME:       s_general_pkg
      PURPOSE:

      REVISIONS:
      Ver        Date        Author           Description
      ---------  ----------  ---------------  ------------------------------------
      1.0        05/01/2012      user1       1. Created this package.
   ******************************************************************************/

   FUNCTION get_next_purchase_line_no (p_purchase_header_id IN NUMBER)
      RETURN NUMBER;
END s_general_pkg;
/

CREATE OR REPLACE PACKAGE BODY s_general_pkg
AS
   FUNCTION get_next_purchase_line_no (p_purchase_header_id IN NUMBER)
      RETURN NUMBER
   IS
      CURSOR c_purchase_line_count (cp_purchase_header_id IN NUMBER)
      IS
         SELECT NVL (COUNT (*), 1)
           FROM purchase_lines
          WHERE purchase_header_id = cp_purchase_header_id;

      l_count   NUMBER;
   BEGIN
      OPEN c_purchase_line_count (cp_purchase_header_id => p_purchase_header_id);

      FETCH c_purchase_line_count INTO l_count;

      CLOSE c_purchase_line_count;

      l_count := l_count + 1;
      RETURN l_count;
   EXCEPTION
      WHEN OTHERS
      THEN
         RETURN 1;
   END get_next_purchase_line_no;
END s_general_pkg;